home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 410_01 / wlist / tstring.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-30  |  2.0 KB  |  86 lines

  1. static char sccs_id[] = "@(#)tstring.cc    1.1 2/15/94 10:38:12";
  2. /*+++
  3.  
  4.   :  :    tstring
  5.  
  6.     PURPOSE : tstring class member function
  7.  
  8.     DATE    : Sun Jan 30 18:30:17 EST 1994
  9.  
  10.     AUTHOR  : W. Hatch
  11.  
  12.     PROJECT : WEH Software
  13.             
  14.     COMPANY : Coleman Research Corporation
  15.           9891 Broken Land Parkway
  16.           Suite 200
  17.           Columbia, Maryland 21045
  18.           Phone (301)621-8600
  19.           FAX (410)7210
  20. ---*/ 
  21. /*
  22. ------------------------------------------------------------------------
  23.   MODIFICATIONS
  24. DATE    PROGRAMMER    DESCRIPTION
  25. ========================================================================
  26. 2-15-94    W. Hatch    added function compare_tstring()
  27. */
  28.  
  29. #include <stdio.h>
  30. #include <string.h>
  31. #include <tstring.h>
  32. //--------------------------------------------------------------------
  33. // constructor and destructor
  34. //--------------------------------------------------------------------
  35. tstring::tstring(){
  36.     ts=(char *)0;
  37. }
  38. tstring::~tstring(){
  39.     delete [] ts;
  40. }
  41. //--------------------------------------------------------------------
  42. // Tstring - access and assign
  43. //--------------------------------------------------------------------
  44. char *tstring::Tstring(){
  45.     return ts;
  46. }
  47. char *tstring::Tstring(char *s){
  48.     delete [] ts;
  49.     ts = (char *)0;
  50.     if(s != (char *)0)
  51.     {
  52.         ts=new char[strlen(s)+1];
  53.         strcpy(ts,s);
  54.         if(strlen(ts) > 1)
  55.         {
  56.             printf("tstrinf::Tstring() bad string %s\n",ts);
  57.         }
  58.     }
  59.     return ts;
  60. }
  61. //--------------------------------------------------------------------
  62. // print - used mostly for debug
  63. //--------------------------------------------------------------------
  64. void tstring::print(FILE *pf){
  65.     if(Tstring() != (char *)0)
  66.         fprintf(pf,"\t\t\ttstring %s\n",Tstring());
  67.     else
  68.         fprintf(pf,"\t\t\ttstring (null)\n");
  69. }
  70. void tstring::print(){
  71.     print(stdout);
  72. }
  73.  
  74. void print_tstring(FILE *pf, void *t){
  75.     tstring *tt=(tstring *)t;
  76.     if(tt!=(tstring *)0 && tt->Tstring() != (char *)0)
  77.         fprintf(pf,"\t\t\ttstring %s\n",tt->Tstring());
  78.     else
  79.         fprintf(pf,"\t\t\ttstring (null)\n");
  80. }
  81. int compare_tstring(void *a, void *b){
  82.  
  83.     return strcmp(((tstring *)a)->Tstring(), 
  84.         ((tstring *)b)->Tstring());
  85. }
  86.